package sigeco.model;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
 * KnowledgeGroup class.
 * 
 * A KnowledgeGroup is an entity that has a title, may have nested (children)
 * KnowledgeGroups and may have Knowledges.
 * 
 * Its purpose is to group Knowledges in categories and sub-categories.
 * 
 * @author julien
 * 
 */
@Entity
@Table(name = "knowledge_groups")
public class KnowledgeGroup {

    private Matrix matrix;
    private KnowledgeGroup parent;
    private List<KnowledgeGroup> children = new ArrayList<KnowledgeGroup>();
    private List<Knowledge> knowledges = new ArrayList<Knowledge>();
    private long id;
    private String title;

    @ManyToOne(optional = false)
    public Matrix getMatrix() {
            return this.matrix;
    }

    public void setMatrix(final Matrix matrix) {
            this.matrix = matrix;
    }

    @ManyToOne
    public KnowledgeGroup getParent() {
            return this.parent;
    }

    public void setParent(final KnowledgeGroup parent) {
            this.parent = parent;
    }

    @OneToMany(targetEntity = KnowledgeGroup.class, mappedBy = "parent", cascade = {CascadeType.ALL})
    public List<KnowledgeGroup> getChildren() {
            return this.children;
    }

    public void setChildren(final List<KnowledgeGroup> children) {
            this.children = children;
    }

    @JoinColumn(nullable = false)
    @OneToMany(targetEntity = Knowledge.class, mappedBy = "knowledgeGroup", cascade = {CascadeType.ALL})
    public List<Knowledge> getKnowledges() {
            return knowledges;
    }

    public void setKnowledges(List<Knowledge> knowledges) {
            this.knowledges = knowledges;
    }
    
    @Id
    @GeneratedValue
    public long getId() {
            return this.id;
    }

    public void setId(final long id) {
            this.id = id;
    }

    public void setTitle(String name) {
        this.title = name;
    }

    @Column(nullable = false)
    public String getTitle() {
        return title;
    }
}
